<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTemporariesTable extends Migration
{
    /**
     * Run the migrations.
     * 临时用工表
     * @return void
     */
    public function up()
    {
        Schema::create('temporaries', function (Blueprint $table) {
            $table->Increments('id');
            $table->string('name')->comment('员工姓名');
            $table->char('sex',1)->comment('性别 0男 1女')->nullable();
            $table->string('id_no')->comment('证件号码')->nullable();
            $table->string('id_start_time')->comment('证件生效日期')->nullable();
            $table->string('id_end_time')->comment('证件失效日期')->nullable();
            $table->string('phone',30)->comment('电话号码')->nullable();
            $table->text('bank_name')->comment('开户行')->nullable();
            $table->string('account')->comment('银行账号')->nullable();
            $table->Integer('organization_id')->unsigned()->comment('所属组织')->nullable();
            $table->foreign('organization_id')->references('id')->on('organizations')->onDelete('set null');
            $table->unsignedInteger('department_id')->unsigned()->comment('所属部门')->nullable();
            $table->foreign('department_id')->references('id')->on('departments')->onDelete('set null');
            $table->Integer('post_id')->comment('岗位')->unsigned()->nullable();
            $table->foreign('post_id')->references('id')->on('posts')->onDelete('set null');
            $table->Integer('skill_id')->comment('职级')->unsigned()->nullable();
            $table->foreign('skill_id')->references('id')->on('skills')->onDelete('set null');
            $table->integer('payroll')->comment('工薪')->unsigned()->nullable();
            $table->integer('wageCategory')->comment('工薪类型')->unsigned()->nullable();
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['id_no','deleted_at']);
        });

        Schema::create('temporary_files', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('temporary_id')->unsigned()->comment('临时员工id')->nullable();
            $table->foreign('temporary_id')->on('temporaries')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图片所属的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('temporary_files');
        Schema::dropIfExists('temporaries');
    }
}
